package com.ctshk.rpc.order.custom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.order.custom.dto.order.CustomOrderTouristRefundListDTO;
import com.ctshk.rpc.order.custom.dto.order.TouristRefundDetailListDTO;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderTouristRefund;
import com.ctshk.rpc.order.custom.entity.CustomizedOrderTouristRefundDetail;
import com.ctshk.rpc.order.custom.provider.CustomOrderTouristRefundProvider;
import com.ctshk.rpc.order.custom.req.order.CustomOrderTouristRefundAddReq;
import com.ctshk.rpc.order.custom.req.order.CustomOrderTouristRefundListReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 游客退款记录 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
public interface CustomizedOrderTouristRefundMapper extends BaseMapper<CustomizedOrderTouristRefund> {

    /**
     * 退款记录列表
     * @param pageParam
     * @param req
     * @return
     */
    @SelectProvider(type = CustomOrderTouristRefundProvider.class, method = "selectListBySelective")
    IPage<CustomOrderTouristRefundListDTO> selectListBySelective(@Param("page") IPage<CustomOrderTouristRefundListReq> pageParam, @Param("req") CustomOrderTouristRefundListReq req);

    /**
     * 团期详情-退款明细
     * @param scheduleId
     * @return
     */
    @SelectProvider(type = CustomOrderTouristRefundProvider.class, method = "scheduleRefundList")
    List<CustomOrderTouristRefundListDTO> scheduleRefundList(@Param("schedule_id") Long scheduleId);

    /**
     * 退款管理-退款明细
     * @param orderId
     * @return
     */
    @SelectProvider(type = CustomOrderTouristRefundProvider.class, method = "refundList")
    List<CustomOrderTouristRefundListDTO> refundList(@Param("order_id") Long orderId);

    @SelectProvider(type = CustomOrderTouristRefundProvider.class, method = "selectAddByRefundDetailTypeId")
    List<CustomizedOrderTouristRefundDetail> selectAddByRefundDetailTypeId(@Param("req") CustomOrderTouristRefundAddReq req,
                                                                       @Param("param1") Set<Long> param1);

    /**
     * 退款明细
     * @param id
     * @return
     */
    @Select("SELECT a.id,a.refund_number,c.cn_surname,c.cn_name,a.refund_type,a.refund_detail,a.currency,a.refund_amount,a.actual_refund_amount,a.refund_account,a.refund_reason,a.remark,a.refund_status,a.gmt_create,a.create_id\n" +
            "FROM t_customized_order_tourist_refund_detail a\n" +
            "LEFT JOIN t_customized_order_tourist_refund b ON a.refund_id = b.id\n" +
            "LEFT JOIN t_customized_order_tourist_info c ON b.tourist_id = c.id\n" +
            "WHERE b.tourist_id = #{tourist_id} AND a.is_deleted = 0")
    List<TouristRefundDetailListDTO> refundDetailList(@Param("tourist_id") Long id);
}
